import java.util.*;

public class ListTest {
    public static int elements = 1000;

    public static void main(String[] args) {
        System.out.println("Testing array list");

        testArrayList(100);
        testArrayList(1_000);
        testArrayList(10_000);
        testArrayList(100_000);
        testArrayList(1_000_000);

        System.out.println("Testing linked list");

        testLinkedList(100);
        testLinkedList(1_000);
        testLinkedList(10_000);
        testLinkedList(100_000);
        testLinkedList(1_000_000);
    }

    public static int[] getRandom(int size) {
        int[] random = new int[elements];
        for (int i = 0; i < elements; i++) {
            random[i] = (int) (Math.random() * size);
        }
        return random;
    }

    public static void testArrayList(int size) {
        testList(size, new ArrayList<>());
    }

    public static void testLinkedList(int size) {
        testList(size, new LinkedList<>());
    }

    public static void testList(int size, List<Object> list) {
        System.out.println("size: " + size + ", " + elements + " elements");

        for (int i = 0; i < size; i++) {
            list.add(new Object());
        }

        int[] random = getRandom(size);

        long startTime, time;
        startTime = System.currentTimeMillis();

        for (int i = 0; i < elements; i++) {
            list.add(random[i], new Object());
        }

        time = System.currentTimeMillis() - startTime;
        time = 1000 * time / elements;

        System.out.println("micro seconds: " + time);
        System.out.println();
    }
}